package com.sinosoft.dsp.system.to.attribute;

import java.io.DataInputStream;
import java.io.DataOutputStream;

import com.sinosoft.dsp.system.core.exception.SinoFileException;
import com.sinosoft.dsp.system.core.i18n.BaseMessages;
import com.sinosoft.dsp.system.to.exception.SinoAttributeException;
import com.sinosoft.dsp.system.to.exception.SinoAttributeValidationException;
import com.sinosoft.dsp.system.to.helper.CommonAttributeType;

/**
 * 属性类型描述接口
 * 
 * @since 1.0 2010-4-21
 * @author 潘巍（Peter Pan）
 * 
 * @param <T>
 */
public interface Attribute<T> {

	/** 表示行记录不以此属性排序 */
	public static final int SORT_TYPE_NOT_SORTED = 0;

	/** 表示行记录以此属性升序排列 */
	public static final int SORT_TYPE_ASCENDING = 1;

	/** 表示行记录以此属性降序排列 */
	public static final int SORT_TYPE_DESCENDING = 2;

	/**
	 * 排序类型代码
	 */
	public static final String[] sortTypeCode = new String[] { "None",
			"Ascending", "Descending", };

	public final static String[] sortTypeDesc = new String[] {
			BaseMessages.getString("Attribute.SortTypeCode." + sortTypeCode[0]),
			BaseMessages.getString("Attribute.SortTypeCode." + sortTypeCode[1]),
			BaseMessages.getString("Attribute.SortTypeCode." + sortTypeCode[2]), };

	/**
	 * 表示字符串不进行修剪
	 */
	public static final int TRIM_TYPE_NONE = 0;

	/**
	 * 表示字符串进行左修剪
	 */
	public static final int TRIM_TYPE_LEFT = 1;

	/**
	 * 表示字符串进行右修剪
	 */
	public static final int TRIM_TYPE_RIGHT = 2;

	/**
	 * 表示字符串进行左右修剪
	 */
	public static final int TRIM_TYPE_BOTH = 3;

	public final static String trimTypeCode[] = { "None", "Left", "Right",
			"Both" };

	public final static String[] trimTypeDesc = new String[] {
			BaseMessages.getString("Attribute.TrimTypeCode." + trimTypeCode[0]),
			BaseMessages.getString("Attribute.TrimTypeCode." + trimTypeCode[1]),
			BaseMessages.getString("Attribute.TrimTypeCode." + trimTypeCode[2]),
			BaseMessages.getString("Attribute.TrimTypeCode." + trimTypeCode[3]), };

	/**
	 * 默认的Integer长度，用于硬编码的元数据integers
	 */
	public static final int DEFAULT_INTEGER_LENGTH = 10;

	/**
	 * 属性原始ID
	 * 
	 * @return
	 */
	public String getId();

	public void setId(String id);

	/** 属性名称 */
	public String getName();

	public void setName(String name);

	/** 长度 */
	public int getLength();

	public void setLength(int length);

	public void setLength(int length, int precision);

	/** 精度 */
	public int getPrecision();

	public void setPrecision(int precision);

	/** 原始值 */
	public String getOrigin();

	public void setOrigin(String origin);

	/** 注释 */
	public String getComments();

	public void setComments(String comments);

	/** 属性类型 */
	public CommonAttributeType getType();

	/** 排序类型 */
	public void setSortType(int type) throws SinoAttributeException;

	public int getSortType();

	public String getSortTypeCode();

	public String getSortTypeDesc();

	/** 裁剪类型 */
	public void setTrimType(int type) throws SinoAttributeException;

	public int getTrimType();

	public String getTrimTypeCode();

	public String getTrimTypeDesc();

	/**
	 * 获得属性值
	 * 
	 * @return
	 * @throws SinoAttributeException
	 */
	public T getValue() throws SinoAttributeException;

	/**
	 * 设定属性值
	 * 
	 * @param v
	 * @throws SinoAttributeException
	 */
	public void setValue(T v) throws SinoAttributeException;

	/**
	 * 判断对象是否为空
	 * 
	 * @return
	 * @throws SinoAttributeException
	 */
	public boolean isNull() throws SinoAttributeException;

	/**
	 * 是否降序排列
	 * 
	 * @return
	 */
	public boolean isSortedDescending();

	public void setSortedDescending(boolean sortedDescending);

	/**
	 * 验证值的合法性
	 * 
	 * @throws SinoAttributeValidationException
	 */
	public void validate() throws SinoAttributeValidationException;

	/**
	 * 转换为字符串
	 * 
	 * @return
	 */
	public String convertToString();

	/**
	 * 通过字符串初始化值
	 * 
	 * @param content
	 */
	public void instantiateFromString(String content)
			throws SinoAttributeException;

	public void instantiateFromObject(Object content)
			throws SinoAttributeException;

	/**
	 * 设置业务概念
	 * 
	 * @param concept
	 */
	public void setConcept(String concept);

	public String getConcept();

	/**
	 * 克隆对象
	 * 
	 * @return
	 * @throws SinoAttributeException
	 */
	public Attribute<T> cloneAttribute() throws SinoAttributeException;

	/**
	 * 将该类的数据写入指定的输出流中
	 * 
	 * @param outputStream
	 * @throws SinoFileException
	 *             如果发生I/O错误
	 * @throws SinoAttributeException
	 */
	public void writeData(DataOutputStream outputStream)
			throws SinoFileException, SinoAttributeException;

	/**
	 * 从指定的输入流中读取数据，反序列化成该对象
	 * 
	 * @param inputStream
	 * @return
	 * @throws SinoFileException
	 */
	public T readData(DataInputStream inputStream) throws SinoFileException;

	/**
	 * 比较
	 * 
	 * @param attributes
	 * @return
	 * @throws SinoAttributeException
	 */
	public int compare(Attribute<?> attributes) throws SinoAttributeException;

	/**
	 * 
	 * @return 是否需要真实复制
	 */
	public boolean requiresRealClone();

}
